package edu.hrbu.spring.dao.impl;

import edu.hrbu.spring.dao.ActDao;
import edu.hrbu.spring.pojo.Act;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author 徐登宇
 */
@Repository
public class ActDaoImpl implements ActDao {

    @Resource
    JdbcTemplate jdbcTemplate;

    @Override
    public Integer selectByNo(Integer no) {
        String sql = "select balance from act where no =?";
        return jdbcTemplate.queryForObject(sql, Integer.class, no);
    }

    @Override
    public Integer updateByNo(Integer no, Integer balance) {
        String sql = "update act set balance =? where no=?";
        return jdbcTemplate.update(sql, balance, no);
    }

    @Override
    public Integer insert(Act act) {
        String sql="insert into act values(?,?)";
        int i = jdbcTemplate.update(sql, act.getNo(), act.getBalance());
        try {
            Thread.sleep(1000*20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return i;
    }
}
